//
//  ElectricityPayViewController.m
//  EasyToo
//
//  Created by linshengqin on 13-9-2.
//
//

#import "ElectricityPayViewController.h"
#import "NetworkAlertView.h"
@interface ElectricityPayViewController ()

@end

@implementation ElectricityPayViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)initMainView
{
    _bgScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [DeviceUtil getScreenWidth], [DeviceUtil getScreenHeight])];
    [self.view addSubview:_bgScrollView];
    _bgScrollView.contentSize = CGSizeMake(320, 700);
    _bgScrollView.showsVerticalScrollIndicator = YES;
    
}

-(void)initDetailView
{
    UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 340)];
    imageView.image = [UIImage imageNamed: @"list2" ];
    //    UIImageView *imageView = [[UIImageView alloc] initWithImage:image] ;
    [_bgScrollView addSubview:imageView];
    
    //[self.view setBackgroundColor: [UIColor colorWithPatternImage: [UIImage imageNamed: @"qq_list"]]];
    // Do any additional setup after loading the view.
    UILabel *label_message = [[UILabel alloc] initWithFrame:CGRectMake(120, 0, 150, 30)];
    label_message.text = @"确认信息";
    label_message.textColor = [UIColor redColor];
    label_message.font = [UIFont systemFontOfSize:20];
    label_message.backgroundColor = [UIColor clearColor];
    [_bgScrollView addSubview:label_message];
    
    int i = 50;
    
    UILabel *label_account = [[UILabel alloc] initWithFrame:CGRectMake(30, i, 250, 20)];
    label_account.font = [UIFont systemFontOfSize:13];
    [label_account setText:[NSString stringWithFormat:@"用户编号 : %@",electricity_model.account]];
    label_account.backgroundColor = [UIColor clearColor];
    
    [_bgScrollView addSubview:label_account];
    
    
    UILabel *label_price = [[UILabel alloc] initWithFrame:CGRectMake(30, i+30, 250, 20)];
    label_price.font = [UIFont systemFontOfSize:13];
    [label_price setText:[NSString stringWithFormat:@"用户名称 : %@",info.userName]];
    label_price.backgroundColor = [UIColor clearColor];
    
    [_bgScrollView addSubview:label_price];
    
    UILabel *label_pay = [[UILabel alloc] initWithFrame:CGRectMake(30, i+60, 250, 20)];
    label_pay.font = [UIFont systemFontOfSize:13];
    [label_pay setText:[NSString stringWithFormat:@"帐单日期 :%@",info.billMonth]];
    //label_pay.text = @"支付方式:%@", self.payType;
    label_pay.backgroundColor = [UIColor clearColor];
    [_bgScrollView addSubview:label_pay];
    
    UILabel *label_pay1 = [[UILabel alloc] initWithFrame:CGRectMake(30, i+90, 250, 20)];
    label_pay1.font = [UIFont systemFontOfSize:13];
    float currentFee = [info.currentFee floatValue]/100;
    [label_pay1 setText:[NSString stringWithFormat:@"本金 : %.2f",currentFee]];
    label_pay1.backgroundColor = [UIColor clearColor];
    
    //label_pay.text = @"支付方式:%@", self.payType;
    [_bgScrollView addSubview:label_pay1];
    
    UILabel *label_pay2 = [[UILabel alloc] initWithFrame:CGRectMake(30, i+130, 250, 20)];
    label_pay2.font = [UIFont systemFontOfSize:13];
    float laterFee = [info.laterFee floatValue]/100;

    [label_pay2 setText:[NSString stringWithFormat:@"滞纳金 : %.2f元",laterFee]];
    //label_pay.text = @"支付方式:%@", self.payType;
    label_pay2.backgroundColor = [UIColor clearColor];
    
    [_bgScrollView addSubview:label_pay2];
    
    UILabel *label_pay3 = [[UILabel alloc] initWithFrame:CGRectMake(30, i+160, 250, 20)];
    label_pay3.font = [UIFont systemFontOfSize:13];
    float consumption = [info.consumption floatValue]/100;
    [label_pay3 setText:[NSString stringWithFormat:@"用电量 : %.2f",consumption]];
    label_pay3.backgroundColor = [UIColor clearColor];
    
    //label_pay.text = @"支付方式:%@", self.payType;
    [_bgScrollView addSubview:label_pay3];
    
    UILabel *label_pay4 = [[UILabel alloc] initWithFrame:CGRectMake(30, i+190, 250, 20)];
    label_pay4.font = [UIFont systemFontOfSize:13];
    [label_pay4 setText:[NSString stringWithFormat:@"联系电话 : %@",electricity_model.phoneNum]];
    //label_pay.text = @"支付方式:%@", self.payType;
    label_pay4.backgroundColor = [UIColor clearColor];
    
    [_bgScrollView addSubview:label_pay4];
    
    UILabel *label_pay5 = [[UILabel alloc] initWithFrame:CGRectMake(30, i+220, 250, 20)];
    label_pay5.font = [UIFont systemFontOfSize:13];
    [label_pay5 setText:[NSString stringWithFormat:@"支付方式 : %@",@"银联"]];
    //label_pay.text = @"支付方式:%@", self.payType;
    label_pay5.backgroundColor = [UIColor clearColor];
    
    [_bgScrollView addSubview:label_pay5];
    
    
    UILabel *label_total = [[UILabel alloc] initWithFrame:CGRectMake(140, i+250, 180, 20)];
    float totalFee = [info.totalFee floatValue]/100;
    [label_total setText:[NSString stringWithFormat:@"合计 :%.2f元",totalFee]];
    label_total.textColor = [UIColor redColor];
    label_total.font = [UIFont systemFontOfSize:18];
    label_total.backgroundColor = [UIColor clearColor];
    [_bgScrollView addSubview:label_total];
    
    UIButton *confirmButton = [[UIButton alloc] initWithFrame:CGRectMake(40, 340, 230, 40)];
    [confirmButton setBackgroundImage:[UIImage imageNamed:@"button_3"] forState:UIControlStateNormal];
    [confirmButton setTitle:@"确认支付" forState:UIControlStateNormal];
    [confirmButton addTarget:self action:@selector(confirmPay:) forControlEvents:UIControlEventTouchUpInside];
    [_bgScrollView addSubview:confirmButton];
}

-(void)confirmPay:(id)sender
{
    [[NetworkAlertView shareView] showNetView];
    NSString* clientID = [electricity_model.account copy];
    NSString* clientName = info.userName;
    NSString* billDate = [electricity_model.month copy];
    NSString* billMonth = info.billMonth;
    NSString* total = info.totalFee;
    [[ElectricityManager shareManager]orderElectricWithClientId:clientID andClientName:clientName andBillDate:billDate andBillMonths:billMonth andTotalFee:total];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
     [self.view setBackgroundColor:BackgroundColor];

    [self initData];
	// Do any additional setup after loading the view.
    [self initMainView];
    [self initDetailView];
}

-(void) initData
{
    electricity_model = [ElectricityModel sharedata];
    [ElectricityManager shareManager].delegate = self;
    info = [electricity_model.electricFeeInfoArray objectAtIndex:0];
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)onOrderElectricFinish:(BOOL)isSuccess Tn:(NSString *)tn
{
    [[NetworkAlertView shareView] delView];
    
    [UPPayPlugin startPay:tn sysProvide:nil spId:nil mode:PAY_MODE_REALEASE viewController:self delegate:self];
}

-(void)UPPayPluginResult:(NSString*)result
{
    NSString *alertString = nil;
    if ([result isEqualToString:@"success"])
    {
        alertString = @"交易成功";
    }
    else if ([result isEqualToString:@"cancel"])
    {
        alertString = @"交易取消";
    }
    else
    {
        alertString = @"交易失败";
    }
    
    UIAlertView *alert = [[UIAlertView alloc]  initWithTitle:@"支付结果" message:alertString  delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [alert show];
    
}


@end
